<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>常见问题(FAQ) | lovewhoilove 的小站</title><meta name="author" content="lovewhoilove"><meta name="copyright" content="lovewhoilove"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="原文链接及内容原文链接：https:&#x2F;&#x2F;openlayers.org&#x2F;doc&#x2F;faq.html   当用户寻求帮助时，某些问题比其他问题更容易出现。本文档尝试列出在Stack Overflow上经常提问的一些问题。如果你认为应该在此处添加一个问题(以及它的答案)，请随时联系我们或在Github上提交一个pr(Pull Request)以增强本文档。  注：额外地，这里用一张图来解释一下上述Pull">
<meta property="og:type" content="website">
<meta property="og:title" content="常见问题(FAQ)">
<meta property="og:url" content="https://lovewhoilove.gitee.io/faq/">
<meta property="og:site_name" content="lovewhoilove 的小站">
<meta property="og:description" content="原文链接及内容原文链接：https:&#x2F;&#x2F;openlayers.org&#x2F;doc&#x2F;faq.html   当用户寻求帮助时，某些问题比其他问题更容易出现。本文档尝试列出在Stack Overflow上经常提问的一些问题。如果你认为应该在此处添加一个问题(以及它的答案)，请随时联系我们或在Github上提交一个pr(Pull Request)以增强本文档。  注：额外地，这里用一张图来解释一下上述Pull">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lovewhoilove.gitee.io/img/avatar.png">
<meta property="article:published_time" content="2023-11-29T01:28:05.183Z">
<meta property="article:modified_time" content="2023-11-29T01:28:05.183Z">
<meta property="article:author" content="lovewhoilove">
<meta property="article:tag" content="GIS,前端,Windows">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lovewhoilove.gitee.io/img/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://lovewhoilove.gitee.io/faq/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="manifest" href="/img/pwa/manifest.json"/><meta name="msapplication-TileColor" content="#49b1f5"/><link rel="apple-touch-icon" sizes="180x180" href="/img/pwa/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/pwa/32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/img/pwa/16.png"/><link rel="mask-icon" href="/img/pwa/32.png" color="#5bbad5"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: lovewhoilove","link":"链接: ","source":"来源: lovewhoilove 的小站","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: false,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '常见问题(FAQ)',
  isPost: false,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-11-29 09:28:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/progress_bar.css"><link rel="stylesheet" href="/css/custom.css"><svg aria-hidden="true" style="position:absolute; overflow:hidden; width:0; height:0"><symbol id="icon-sun" viewBox="0 0 1024 1024"><path d="M960 512l-128 128v192h-192l-128 128-128-128H192v-192l-128-128 128-128V192h192l128-128 128 128h192v192z" fill="#FFD878" p-id="8420"></path><path d="M736 512a224 224 0 1 0-448 0 224 224 0 1 0 448 0z" fill="#FFE4A9" p-id="8421"></path><path d="M512 109.248L626.752 224H800v173.248L914.752 512 800 626.752V800h-173.248L512 914.752 397.248 800H224v-173.248L109.248 512 224 397.248V224h173.248L512 109.248M512 64l-128 128H192v192l-128 128 128 128v192h192l128 128 128-128h192v-192l128-128-128-128V192h-192l-128-128z" fill="#4D5152" p-id="8422"></path><path d="M512 320c105.888 0 192 86.112 192 192s-86.112 192-192 192-192-86.112-192-192 86.112-192 192-192m0-32a224 224 0 1 0 0 448 224 224 0 0 0 0-448z" fill="#4D5152" p-id="8423"></path></symbol><symbol id="icon-moon" viewBox="0 0 1024 1024"><path d="M611.370667 167.082667a445.013333 445.013333 0 0 1-38.4 161.834666 477.824 477.824 0 0 1-244.736 244.394667 445.141333 445.141333 0 0 1-161.109334 38.058667 85.077333 85.077333 0 0 0-65.066666 135.722666A462.08 462.08 0 1 0 747.093333 102.058667a85.077333 85.077333 0 0 0-135.722666 65.024z" fill="#FFB531" p-id="11345"></path><path d="M329.728 274.133333l35.157333-35.157333a21.333333 21.333333 0 1 0-30.165333-30.165333l-35.157333 35.157333-35.114667-35.157333a21.333333 21.333333 0 0 0-30.165333 30.165333l35.114666 35.157333-35.114666 35.157334a21.333333 21.333333 0 1 0 30.165333 30.165333l35.114667-35.157333 35.157333 35.157333a21.333333 21.333333 0 1 0 30.165333-30.165333z" fill="#030835" p-id="11346"></path></symbol></svg><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><div class="loading-img"></div><div class="loading-image-dot"></div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (true) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><link rel="stylesheet" href="/css/custom.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "/img/friend_404.gif" data-lazy-src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">250</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">327</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-newspaper"></i><span> 文章相关</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-timeline"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-layer-group"></i><span> Openlayers</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/doc/"><i class="fa-fw fas fa-book-reader"></i><span> 说明文档</span></a></li><li><a class="site-page child" href="/quick-start/"><i class="fa-fw fas fa-bolt"></i><span> 快速入门</span></a></li><li><a class="site-page child" href="/tutorials/"><i class="fa-fw fas fa-book"></i><span> 教程</span></a></li><li><a class="site-page child" href="/faq/"><i class="fa-fw fas fa-question"></i><span> 常见问题</span></a></li><li><a class="site-page child" href="/workshop/"><i class="fa-fw fas fa-graduation-cap"></i><span> 研讨会</span></a></li><li><a class="site-page child" href="/examples/"><i class="fa-fw fas fa-laptop-code"></i><span> 示例</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 网址导航</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="not-home-page" id="page-header" style="background-image: url('/img/homepage-banner.webp')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">lovewhoilove 的小站</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-newspaper"></i><span> 文章相关</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-timeline"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-layer-group"></i><span> Openlayers</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/doc/"><i class="fa-fw fas fa-book-reader"></i><span> 说明文档</span></a></li><li><a class="site-page child" href="/quick-start/"><i class="fa-fw fas fa-bolt"></i><span> 快速入门</span></a></li><li><a class="site-page child" href="/tutorials/"><i class="fa-fw fas fa-book"></i><span> 教程</span></a></li><li><a class="site-page child" href="/faq/"><i class="fa-fw fas fa-question"></i><span> 常见问题</span></a></li><li><a class="site-page child" href="/workshop/"><i class="fa-fw fas fa-graduation-cap"></i><span> 研讨会</span></a></li><li><a class="site-page child" href="/examples/"><i class="fa-fw fas fa-laptop-code"></i><span> 示例</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 网址导航</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="page-site-info"><h1 id="site-title">常见问题(FAQ)</h1></div></header><main class="layout" id="content-inner"><div id="page"><div id="article-container"><details class="toggle" style="border: 1px solid black"><summary class="toggle-button" style="background-color: black;color: #fff">原文链接及内容</summary><div class="toggle-content"><p>原文链接：<a target="_blank" rel="noopener" href="https://openlayers.org/doc/faq.html">https://openlayers.org/doc/faq.html</a></p>
<iframe src="https://openlayers.org/doc/faq.html" width="100%" height="400px" frameborder="0" seamless></iframe></div></details>

<p>当用户寻求帮助时，某些问题比其他问题更容易出现。本文档尝试列出在<a target="_blank" rel="noopener" href="https://stackoverflow.com/questions/tagged/openlayers">Stack Overflow</a>上经常提问的一些问题。<br>如果你认为应该在此处添加一个问题(以及它的答案)，请随时联系我们或在Github上提交一个pr(Pull Request)以增强本文档。</p>
<blockquote>
<p>注：额外地，这里用一张图来解释一下上述Pull Request的意思：<br><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/v2-aabb20757ee5f154d8f682d0438e6f35_r.jpg?imageMogr2/quality/75/format/webp/interlace/0" width="280"/></p>
</blockquote>
<h2 id="OpenLayers使用的是什么投影？"><a href="#OpenLayers使用的是什么投影？" class="headerlink" title="OpenLayers使用的是什么投影？"></a>OpenLayers使用的是什么投影？</h2><p>使用OpenLayers创建的每个地图都将有一个地图视图(View)，每个视图都将有一个投影，这是因为地球是三维的和圆形的，但地图是2D视图，因此我们需要一个数学表达式来呈现它，这便是<strong>投影</strong>。<br>实际上不只是有一种投影，而是有许多常见的投影，每个投影都有不同的属性，因为它可以准确地表示距离、角度或面积。某些投影可能更适合世界的不同地区(区域)。<br>回到最初的问题：OpenLayers能够处理大多数投影。如果你没有明确设置投影，那么地图将使用Openlayers的默认设置，即<code>Web墨卡托投影</code>(<code>EPSG：3857</code>)。同样地，投影也用于OpenStreetMap项目的地图，以及商业化产品像必应地图或谷歌地图。<br>如果你想要一张显示整个世界的地图，上述<code>Web墨卡托投影</code>是一个很好的选择，如果你想使用OpenStreetMap或Bing瓦片地图，也同样需要使用这个投影。</p>
<h2 id="如何更改地图的投影？"><a href="#如何更改地图的投影？" class="headerlink" title="如何更改地图的投影？"></a>如何更改地图的投影？</h2><p>实际上，你很有可能希望将OpenLayers的默认投影更改为更适合你所在地区的投影，或着是特定数据的投影。<br>地图的投影可以通过<code>View</code>对象属性进行设置，以下是一些例子：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// OpenLayers支持WGS84坐标系(EPSG:4326)的支持</span></span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">projection</span>: <span class="string">&#x27;EPSG:4326&#x27;</span></span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> proj4 <span class="keyword">from</span> <span class="string">&#x27;proj4&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;register&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj/proj4.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;get <span class="keyword">as</span> getProjection&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 要使用其他投影，则必须在OpenLayers中注册投影，</span></span><br><span class="line"><span class="comment">// 这可以通过[proj4](http://proj4js.org/)库轻松完成。</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">// 默认情况下，OpenLayers不知道`EPSG:21781`(Swiss)投影，</span></span><br><span class="line"><span class="comment">// 因此，我们需要为`EPSG:21781`创建了一个投影实例，并将其注册，</span></span><br><span class="line"><span class="comment">// 以使Openlayers库可以通过其代码(即EPSG代码)进行查找。</span></span><br><span class="line">proj4.<span class="title function_">defs</span>(<span class="string">&#x27;EPSG:21781&#x27;</span>,</span><br><span class="line">  <span class="string">&#x27;+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 &#x27;</span> +</span><br><span class="line">  <span class="string">&#x27;+x_0=600000 +y_0=200000 +ellps=bessel &#x27;</span> +</span><br><span class="line">  <span class="string">&#x27;+towgs84=660.077,13.551,369.344,2.484,1.783,2.939,5.66 +units=m +no_defs&#x27;</span>);</span><br><span class="line"><span class="title function_">register</span>(proj4);</span><br><span class="line"><span class="keyword">const</span> swissProjection = <span class="title function_">getProjection</span>(<span class="string">&#x27;EPSG:21781&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//注册后便可以使用上Swiss述投影</span></span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">projection</span>: swissProjection</span><br><span class="line">    <span class="comment">// ...</span></span><br><span class="line">  &#125;)</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>我们建议在<a target="_blank" rel="noopener" href="https://epsg.io/">epsg.io</a>上查找投影的参数(如有效性范围)。</p>
<h2 id="为什么我的地图以几内亚湾-或非洲、海洋、空岛-为中心？"><a href="#为什么我的地图以几内亚湾-或非洲、海洋、空岛-为中心？" class="headerlink" title="为什么我的地图以几内亚湾(或非洲、海洋、空岛)为中心？"></a>为什么我的地图以几内亚湾(或非洲、海洋、空岛)为中心？</h2><p>如果你在地图视图中设置了一个中心(center)，但在视觉输出中没有看到真正的变化，那么很可能你在错误的投影中提供了地图中心的坐标(即坐标不匹配当前投影)。<br>由于OpenLayers中的默认投影是Web墨卡托(如上所述)，因此必须提供在该投影下的中心的坐标，你的地图很可能如下所示：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">TileLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Tile.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="variable constant_">OSM</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/OSM.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> washingtonLonLat = [-<span class="number">77.036667</span>, <span class="number">38.895</span>];</span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">layers</span>: [</span><br><span class="line">    <span class="keyword">new</span> <span class="title class_">TileLayer</span>(&#123;</span><br><span class="line">      <span class="attr">source</span>: <span class="keyword">new</span> <span class="title function_">OSM</span>()</span><br><span class="line">    &#125;)</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">target</span>: <span class="string">&#x27;map&#x27;</span>,</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">center</span>: washingtonLonLat,</span><br><span class="line">    <span class="attr">zoom</span>: <span class="number">12</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>这里提供了[-77.036667，38.895]作为视图的中心，但由于Web墨卡托是公制投影(以米为单位)，因此这么设置会告诉OpenLayers，中心应该距离[0，0]几米(分别为<code>-77m</code>和<code>-39m</code>)而在Web墨卡托投影中，坐标正好在几内亚湾。</p>
<p>解决方法很简单：提供投影到Web墨卡托的坐标。OpenLayers提供了一些有用的方法来帮助你：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">TileLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Tile.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="variable constant_">OSM</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/OSM.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;fromLonLat&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> washingtonLonLat = [-<span class="number">77.036667</span>, <span class="number">38.895</span>];</span><br><span class="line"><span class="keyword">const</span> washingtonWebMercator = <span class="title function_">fromLonLat</span>(washingtonLonLat);</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">layers</span>: [</span><br><span class="line">    <span class="keyword">new</span> <span class="title class_">TileLayer</span>(&#123;</span><br><span class="line">      <span class="attr">source</span>: <span class="keyword">new</span> <span class="title function_">OSM</span>()</span><br><span class="line">    &#125;)</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">target</span>: <span class="string">&#x27;map&#x27;</span>,</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">center</span>: washingtonWebMercator,</span><br><span class="line">    <span class="attr">zoom</span>: <span class="number">8</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p><code>fromLonLat()</code>方法从Openlayers的3.5版开始可用。<br>如果你在Openlayers中注册一个自定义投影(见上面)，你可以使用下面的方法将一个坐标从WGS84转换到你的投影:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123;transform&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj.js&#x27;</span>;</span><br><span class="line"><span class="comment">// 这里假设已经注册21871投影</span></span><br><span class="line"><span class="keyword">const</span> swissCoord = <span class="title function_">transform</span>([<span class="number">8.23</span>, <span class="number">46.86</span>], <span class="string">&#x27;EPSG:4326&#x27;</span>, <span class="string">&#x27;EPSG:21781&#x27;</span>);</span><br></pre></td></tr></table></figure>
<h2 id="为什么坐标顺序是-经度，纬度-，而不是-纬度，经度-？"><a href="#为什么坐标顺序是-经度，纬度-，而不是-纬度，经度-？" class="headerlink" title="为什么坐标顺序是[经度，纬度]，而不是[纬度，经度]？"></a>为什么坐标顺序是[经度，纬度]，而不是[纬度，经度]？</h2><p>因为有两种不同且互不相容的约定。坐标通常是按纬度和经度这个顺序给出的。地图是地球表面的二维投影，坐标使用的<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E7%AC%9B%E5%8D%A1%E5%B0%94%E5%9D%90%E6%A0%87%E7%B3%BB">笛卡尔坐标系</a>的x,y网格表示，因为按照惯例，它们是在左边画西边，在上面画北边，这意味着x代表经度，y代表纬度。如上所述，OpenLayers旨在处理所有投影，但默认视图是在投影的笛卡尔坐标中。在笛卡尔x，y坐标系和经纬度系统中没有必要使用重复函数来处理坐标，因此输入纬度和经度时应将它们视为笛卡尔坐标，换句话说，书写顺序是<code>lon,lat</code>。<br>如果你记不住是哪个方向，可以使用英语的语言代码<code>en</code>作为助记符：先东(east)后北(north)。</p>
<h3 id="一个实际的例子"><a href="#一个实际的例子" class="headerlink" title="一个实际的例子"></a>一个实际的例子</h3><p>倘若你想要将你的地图放在地球上的某个地方，显然你需要有它的坐标。假设你希望地图以奥地利一个美丽的地方<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E6%96%BD%E6%8B%89%E5%BE%B7%E6%98%8E">Schladming</a>为中心，打开维基百科的这个页面：<a target="_blank" rel="noopener" href="https://zh.wikipedia.org/wiki/%E6%96%BD%E6%8B%89%E5%BE%B7%E6%98%8E">https://zh.wikipedia.org/wiki/%E6%96%BD%E6%8B%89%E5%BE%B7%E6%98%8E</a> ，如下图在右上角有这个地方的坐标：<br><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/Snipaste_2023-04-05_16-00-59.png?imageMogr2/quality/75/format/webp/interlace/0" alt="查看Schladming的坐标"><br>上述坐标如下：<br>WGS84:<br>47° 23′ 39″ N, 13° 41′ 21″ E<br>47.394167, 13.689167</p>
<p>因此，下一步是将转换后的小数坐标放入一个数组中，并将其用作地图视图的中心坐标：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">TileLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Tile.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="variable constant_">OSM</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/OSM.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;fromLonLat&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> schladming = [<span class="number">47.394167</span>, <span class="number">13.689167</span>];</span><br><span class="line"><span class="comment">// 因为我们使用的是OSM(即Web墨卡托投影)，所以我们必须转换坐标...</span></span><br><span class="line"><span class="keyword">const</span> schladmingWebMercator = <span class="title function_">fromLonLat</span>(schladming);</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">layers</span>: [</span><br><span class="line">    <span class="keyword">new</span> <span class="title class_">TileLayer</span>(&#123;</span><br><span class="line">      <span class="attr">source</span>: <span class="keyword">new</span> <span class="title function_">OSM</span>()</span><br><span class="line">    &#125;)</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">target</span>: <span class="string">&#x27;map&#x27;</span>,</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">center</span>: schladmingWebMercator,</span><br><span class="line">    <span class="attr">zoom</span>: <span class="number">9</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>运行上面的例子可能会让你大吃一惊，因为我们的中心不是奥地利的施拉德明，而是也门的一个地区阿比扬(可能也是一个好地方)。那到底发生了什么？<br>许多人混淆了坐标数组中的经度和纬度的顺序，如果你一开始弄错了也不用担心，许多OpenLayers开发者在尝试改变地图中心的时候，不得不再三考虑是先放经度还是先放纬度。那么，让我们反转一下坐标：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> schladming = [<span class="number">13.689167</span>, <span class="number">47.394167</span>];</span><br><span class="line"><span class="comment">//其余代码略</span></span><br></pre></td></tr></table></figure>
<p>现在，Schladming现在正确地显示在地图的中央。<br>因此，当你在OpenLayers中处理<code>EPSG:4326</code>坐标时，请将经度放在前面，然后是纬度。这种行为与我们在OpenLayers 2中所看到的是一样的，因为按照WGS84坐标轴顺序还真说的通（上述的先东后北）。<br>如果你实在记不住正确的顺序，只需看看我们使用的方法名：<code>fromLonLat</code>，暗示我们需要先写经度，后写纬度。</p>
<h2 id="为什么我的数据源中没有任何要素？"><a href="#为什么我的数据源中没有任何要素？" class="headerlink" title="为什么我的数据源中没有任何要素？"></a>为什么我的数据源中没有任何要素？</h2><p>假设你要加载KML文件并在地图上显示包含的要素，可以使用如下代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">VectorLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Vector.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">KMLSource</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/KML.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> vector = <span class="keyword">new</span> <span class="title class_">VectorLayer</span>(&#123;</span><br><span class="line">  <span class="attr">source</span>: <span class="keyword">new</span> <span class="title class_">KMLSource</span>(&#123;</span><br><span class="line">    <span class="attr">projection</span>: <span class="string">&#x27;EPSG:3857&#x27;</span>,</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;data/kml/2012-02-10.kml&#x27;</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>你可能会问自己该KML文件中有多少个要素，并尝试如下所示：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">VectorLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Vector.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">KMLSource</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/KML.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> vector = <span class="keyword">new</span> <span class="title class_">VectorLayer</span>(&#123;</span><br><span class="line">  <span class="attr">source</span>: <span class="keyword">new</span> <span class="title class_">KMLSource</span>(&#123;</span><br><span class="line">    <span class="attr">projection</span>: <span class="string">&#x27;EPSG:3857&#x27;</span>,</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;data/kml/2012-02-10.kml&#x27;</span></span><br><span class="line">  &#125;)</span><br><span class="line">&#125;);</span><br><span class="line"><span class="keyword">const</span> numFeatures = vector.<span class="title function_">getSource</span>().<span class="title function_">getFeatures</span>().<span class="property">length</span>;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;Count right after construction: &quot;</span> + numFeatures);</span><br></pre></td></tr></table></figure>
<p>这将在控制台的日志中记录0个要素的计数。这是因为KML文件的加载将以<strong>异步</strong>方式进行。要尽快获得计数(就在提取文件并且在数据源对象中添加要素之后)，你应该在数据源上使用事件侦听器函数：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vector.<span class="title function_">getSource</span>().<span class="title function_">on</span>(<span class="string">&#x27;change&#x27;</span>, <span class="keyword">function</span>(<span class="params">evt</span>)&#123;</span><br><span class="line">  <span class="keyword">const</span> source = evt.<span class="property">target</span>;</span><br><span class="line">  <span class="keyword">if</span> (source.<span class="title function_">getState</span>() === <span class="string">&#x27;ready&#x27;</span>) &#123;</span><br><span class="line">    <span class="keyword">const</span> numFeatures = source.<span class="title function_">getFeatures</span>().<span class="property">length</span>;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;Count after change: &quot;</span> + numFeatures);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>这时才能获取正确的要素数量，不出意外的话结果应为1119。</p>
<h2 id="如何强制重新渲染地图？"><a href="#如何强制重新渲染地图？" class="headerlink" title="如何强制重新渲染地图？"></a>如何强制重新渲染地图？</h2><p>通常，一旦数据源对象发生更改(例如，当远程数据源已加载时)，就会自动重新渲染地图。<br>若要手动触发渲染，则可以使用：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">map.<span class="title function_">render</span>();</span><br></pre></td></tr></table></figure>
<p>或者上述方法的伴随方法(companion method)：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">map.<span class="title function_">renderSync</span>();</span><br></pre></td></tr></table></figure>
<h2 id="为什么找不到我加载的要素？"><a href="#为什么找不到我加载的要素？" class="headerlink" title="为什么找不到我加载的要素？"></a>为什么找不到我加载的要素？</h2><p>在使用Map的<code>forEachFeatureAtPixel</code>或<code>hasFeatureAtPixel</code>方法时，会发现它们有时不适用于大图标或标签，命中检测仅检查在给定位置的特定距离内的要素。针对大图标，要素的实际几何形状可能由于太远而不会被考虑。<br>在这种情况下，设置VectorLayer的renderBuffer属性(默认值是100px):</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">VectorLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Vector.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> vectorLayer = <span class="keyword">new</span> <span class="title class_">VectorLayer</span>(&#123;</span><br><span class="line">  ...</span><br><span class="line">  <span class="attr">renderBuffer</span>: <span class="number">200</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>推荐值为最大符号、线宽或标签的大小。</p>
<h2 id="为什么在地图上进行缩放或单击时会被关闭-或译为不起作用-或变得不准确？"><a href="#为什么在地图上进行缩放或单击时会被关闭-或译为不起作用-或变得不准确？" class="headerlink" title="为什么在地图上进行缩放或单击时会被关闭(或译为不起作用)或变得不准确？"></a>为什么在地图上进行缩放或单击时会被关闭(或译为不起作用)或变得不准确？</h2><p>在调整地图容器元素的大小时，若OpenLayers没有更新地图，这可能是由渐进式更新CSS样式或手动调整地图大小引起的。当这种情况发生时，任何交互都将会变得不准确: 地图将放大和缩小，并最终不在指针(鼠标指针)上居中。这使得很难进行某些交互，例如选择所需的要素。<br>目前没有内置的方法来对元素的大小变化做出反应，因为<a target="_blank" rel="noopener" href="https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver">Resize Observer API</a>只在Chrome中实现。<br>然而有一种简单解决办法，那便是使用<a target="_blank" rel="noopener" href="https://github.com/que-etc/resize-observer-polyfill">polyfill</a>：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">ResizeObserver</span> <span class="keyword">from</span> <span class="string">&#x27;resize-observer-polyfill&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> mapElement = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#map&#x27;</span>);</span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">target</span>: mapElement</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> sizeObserver = <span class="keyword">new</span> <span class="title class_">ResizeObserver</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">  map.<span class="title function_">updateSize</span>()</span><br><span class="line">&#125;);</span><br><span class="line">sizeObserver.<span class="title function_">observe</span>(mapElement);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 当地图被销毁时调用的方法</span></span><br><span class="line"><span class="comment">// sizeObserver.disconnect()</span></span><br></pre></td></tr></table></figure>
</div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "/img/friend_404.gif" data-lazy-src="/img/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">lovewhoilove</div><div class="author-info__description">生活原本沉闷，但跑起来就有风</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">250</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">327</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">陆陆续续尝试翻译Openlayers API文档，并尝试用实例来深入学习。</div></div><div class="card-widget tzy-right-widget" id="card-wechat"><div id="flip-wrapper"><div id="flip-content"><div class="face"></div><div class="back face"></div></div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#OpenLayers%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%E4%BB%80%E4%B9%88%E6%8A%95%E5%BD%B1%EF%BC%9F"><span class="toc-number">1.</span> <span class="toc-text">OpenLayers使用的是什么投影？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9%E5%9C%B0%E5%9B%BE%E7%9A%84%E6%8A%95%E5%BD%B1%EF%BC%9F"><span class="toc-number">2.</span> <span class="toc-text">如何更改地图的投影？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84%E5%9C%B0%E5%9B%BE%E4%BB%A5%E5%87%A0%E5%86%85%E4%BA%9A%E6%B9%BE-%E6%88%96%E9%9D%9E%E6%B4%B2%E3%80%81%E6%B5%B7%E6%B4%8B%E3%80%81%E7%A9%BA%E5%B2%9B-%E4%B8%BA%E4%B8%AD%E5%BF%83%EF%BC%9F"><span class="toc-number">3.</span> <span class="toc-text">为什么我的地图以几内亚湾(或非洲、海洋、空岛)为中心？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9D%90%E6%A0%87%E9%A1%BA%E5%BA%8F%E6%98%AF-%E7%BB%8F%E5%BA%A6%EF%BC%8C%E7%BA%AC%E5%BA%A6-%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF-%E7%BA%AC%E5%BA%A6%EF%BC%8C%E7%BB%8F%E5%BA%A6-%EF%BC%9F"><span class="toc-number">4.</span> <span class="toc-text">为什么坐标顺序是[经度，纬度]，而不是[纬度，经度]？</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E4%B8%AA%E5%AE%9E%E9%99%85%E7%9A%84%E4%BE%8B%E5%AD%90"><span class="toc-number">4.1.</span> <span class="toc-text">一个实际的例子</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84%E6%95%B0%E6%8D%AE%E6%BA%90%E4%B8%AD%E6%B2%A1%E6%9C%89%E4%BB%BB%E4%BD%95%E8%A6%81%E7%B4%A0%EF%BC%9F"><span class="toc-number">5.</span> <span class="toc-text">为什么我的数据源中没有任何要素？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%BC%BA%E5%88%B6%E9%87%8D%E6%96%B0%E6%B8%B2%E6%9F%93%E5%9C%B0%E5%9B%BE%EF%BC%9F"><span class="toc-number">6.</span> <span class="toc-text">如何强制重新渲染地图？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%89%BE%E4%B8%8D%E5%88%B0%E6%88%91%E5%8A%A0%E8%BD%BD%E7%9A%84%E8%A6%81%E7%B4%A0%EF%BC%9F"><span class="toc-number">7.</span> <span class="toc-text">为什么找不到我加载的要素？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9C%A8%E5%9C%B0%E5%9B%BE%E4%B8%8A%E8%BF%9B%E8%A1%8C%E7%BC%A9%E6%94%BE%E6%88%96%E5%8D%95%E5%87%BB%E6%97%B6%E4%BC%9A%E8%A2%AB%E5%85%B3%E9%97%AD-%E6%88%96%E8%AF%91%E4%B8%BA%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8-%E6%88%96%E5%8F%98%E5%BE%97%E4%B8%8D%E5%87%86%E7%A1%AE%EF%BC%9F"><span class="toc-number">8.</span> <span class="toc-text">为什么在地图上进行缩放或单击时会被关闭(或译为不起作用)或变得不准确？</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/965064e3/" title="ol/style/Style【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202403232115680.png?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ol/style/Style【译】"/></a><div class="content"><a class="title" href="/posts/965064e3/" title="ol/style/Style【译】">ol/style/Style【译】</a><time datetime="2024-03-23T12:42:29.000Z" title="发表于 2024-03-23 20:42:29">2024-03-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/b0659e71/" title="OGC矢量切片(地理)【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202304212152162.jpg?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="OGC矢量切片(地理)【译】"/></a><div class="content"><a class="title" href="/posts/b0659e71/" title="OGC矢量切片(地理)【译】">OGC矢量切片(地理)【译】</a><time datetime="2024-03-10T13:51:44.000Z" title="发表于 2024-03-10 21:51:44">2024-03-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/33015ef3/" title="谷歌地图【译】">谷歌地图【译】</a><time datetime="2024-03-10T13:21:31.000Z" title="发表于 2024-03-10 21:21:31">2024-03-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/38077f94/" title="悬停提示【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202311162246793.jpg?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="悬停提示【译】"/></a><div class="content"><a class="title" href="/posts/38077f94/" title="悬停提示【译】">悬停提示【译】</a><time datetime="2023-11-16T13:22:47.000Z" title="发表于 2023-11-16 21:22:47">2023-11-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5c98ce7f/" title="居住地渲染【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202311162246139.jpg?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="居住地渲染【译】"/></a><div class="content"><a class="title" href="/posts/5c98ce7f/" title="居住地渲染【译】">居住地渲染【译】</a><time datetime="2023-11-16T12:25:46.000Z" title="发表于 2023-11-16 20:25:46">2023-11-16</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/GIS%E8%B5%84%E6%BA%90/"><span class="card-category-list-name">GIS资源</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Openlayers/"><span class="card-category-list-name">Openlayers</span><span class="card-category-list-count">249</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/epsg4326/" style="font-size: 1.17em; color: rgb(178, 199, 185)">epsg4326<sup>2</sup></a><a href="/tags/vectortiles/" style="font-size: 1.22em; color: rgb(29, 33, 82)">vectortiles<sup>5</sup></a><a href="/tags/mapboxstyle/" style="font-size: 1.17em; color: rgb(15, 134, 104)">mapboxstyle<sup>2</sup></a><a href="/tags/ol-mapbox-style/" style="font-size: 1.17em; color: rgb(66, 61, 118)">ol-mapbox-style<sup>2</sup></a><a href="/tags/maptiler/" style="font-size: 1.42em; color: rgb(47, 53, 179)">maptiler<sup>26</sup></a><a href="/tags/grid/" style="font-size: 1.3em; color: rgb(62, 0, 171)">grid<sup>8</sup></a><a href="/tags/vector/" style="font-size: 1.45em; color: rgb(122, 141, 91)">vector<sup>79</sup></a><a href="/tags/esri/" style="font-size: 1.2em; color: rgb(80, 27, 64)">esri<sup>3</sup></a><a href="/tags/ArcGIS/" style="font-size: 1.2em; color: rgb(90, 162, 195)">ArcGIS<sup>3</sup></a><a href="/tags/REST/" style="font-size: 1.2em; color: rgb(5, 80, 21)">REST<sup>3</sup></a><a href="/tags/Feature/" style="font-size: 1.17em; color: rgb(90, 66, 38)">Feature<sup>2</sup></a><a href="/tags/Service/" style="font-size: 1.17em; color: rgb(16, 150, 98)">Service<sup>2</sup></a><a href="/tags/loading/" style="font-size: 1.3em; color: rgb(85, 148, 112)">loading<sup>8</sup></a><a href="/tags/server/" style="font-size: 1.22em; color: rgb(198, 120, 68)">server<sup>5</sup></a><a href="/tags/arcgis/" style="font-size: 1.17em; color: rgb(175, 61, 155)">arcgis<sup>2</sup></a><a href="/tags/image/" style="font-size: 1.27em; color: rgb(65, 15, 82)">image<sup>7</sup></a><a href="/tags/dynamiclayer/" style="font-size: 1.15em; color: rgb(148, 57, 199)">dynamiclayer<sup>1</sup></a><a href="/tags/cog/" style="font-size: 1.35em; color: rgb(189, 169, 52)">cog<sup>13</sup></a><a href="/tags/ndvi/" style="font-size: 1.2em; color: rgb(13, 59, 113)">ndvi<sup>3</sup></a><a href="/tags/ndwi/" style="font-size: 1.15em; color: rgb(117, 111, 93)">ndwi<sup>1</sup></a><a href="/tags/sentinel/" style="font-size: 1.15em; color: rgb(20, 97, 175)">sentinel<sup>1</sup></a><a href="/tags/geotiff/" style="font-size: 1.17em; color: rgb(185, 21, 139)">geotiff<sup>2</sup></a><a href="/tags/projection/" style="font-size: 1.35em; color: rgb(101, 81, 193)">projection<sup>13</sup></a><a href="/tags/proj4js/" style="font-size: 1.25em; color: rgb(2, 186, 14)">proj4js<sup>6</sup></a><a href="/tags/layers/" style="font-size: 1.17em; color: rgb(16, 21, 145)">layers<sup>2</sup></a><a href="/tags/openstreetmap/" style="font-size: 1.4em; color: rgb(195, 147, 183)">openstreetmap<sup>22</sup></a><a href="/tags/canvas/" style="font-size: 1.25em; color: rgb(92, 64, 189)">canvas<sup>6</sup></a><a href="/tags/simple/" style="font-size: 1.22em; color: rgb(31, 140, 103)">simple<sup>5</sup></a><a href="/tags/attribution/" style="font-size: 1.15em; color: rgb(64, 1, 66)">attribution<sup>1</sup></a><a href="/tags/animation/" style="font-size: 1.22em; color: rgb(74, 75, 74)">animation<sup>5</sup></a><a href="/tags/style/" style="font-size: 1.42em; color: rgb(191, 64, 102)">style<sup>26</sup></a><a href="/tags/icon/" style="font-size: 1.32em; color: rgb(183, 155, 162)">icon<sup>9</sup></a><a href="/tags/gif/" style="font-size: 1.15em; color: rgb(68, 124, 131)">gif<sup>1</sup></a><a href="/tags/GPX/" style="font-size: 1.15em; color: rgb(18, 194, 2)">GPX<sup>1</sup></a><a href="/tags/geojson/" style="font-size: 1.32em; color: rgb(56, 78, 58)">geojson<sup>9</sup></a><a href="/tags/tilepyramid/" style="font-size: 1.15em; color: rgb(138, 68, 144)">tilepyramid<sup>1</sup></a><a href="/tags/stac/" style="font-size: 1.17em; color: rgb(88, 193, 62)">stac<sup>2</sup></a><a href="/tags/webgl/" style="font-size: 1.38em; color: rgb(140, 94, 67)">webgl<sup>17</sup></a><a href="/tags/reprojection/" style="font-size: 1.3em; color: rgb(73, 142, 68)">reprojection<sup>8</sup></a><a href="/tags/complex-geometry/" style="font-size: 1.15em; color: rgb(29, 84, 72)">complex-geometry<sup>1</sup></a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>时间轴</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/03/"><span class="card-archive-list-date">三月 2024</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/11/"><span class="card-archive-list-date">十一月 2023</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/10/"><span class="card-archive-list-date">十月 2023</span><span class="card-archive-list-count">11</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/05/"><span class="card-archive-list-date">五月 2023</span><span class="card-archive-list-count">52</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/04/"><span class="card-archive-list-date">四月 2023</span><span class="card-archive-list-count">181</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/01/"><span class="card-archive-list-date">一月 2023</span><span class="card-archive-list-count">1</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">250</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2022-12-13T16:00:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">177.9k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2024-04-25T00:57:24.420Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/homepage-banner.webp')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2024 <i style="color:red" class="fa fa-heartbeat fa-beat"></i> By lovewhoilove</div><div class="footer_custom_text">生活原本沉闷，但跑起来就有风🎈</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"></div><div id="rightside-config-show"><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a class="icon-V hidden" onclick="switchNightMode()" title="浅色和深色模式转换"><svg width="25" height="25" viewBox="0 0 1024 1024"><use id="modeicon" xlink:href="#icon-moon"></use></svg></a><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight, 500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 's2D3RXeuiTBrJjXpdIo4bJuK-gzGzoHsz',
      appKey: 'e6j6L6lA50bj18TlkcZEMw0O',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, {"placeholder":"畅所欲言哈😁~~"}))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script src="/js/sun_moon.js"></script><script src="/js/jquery.min.js"></script><script data-pjax defer src="/js/chocolate.js"></script><script defer type="text/javascript" src="/js/sweetalert2.all.js"></script><script defer src="/js/lunar.js"></script><script defer src="/js/day.js"></script><script data-pjax defer src="/js/fishes.js"></script><canvas id="universe"></canvas><script src="/js/universe.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '2s');
    arr[i].setAttribute('data-wow-delay', '1s');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow_init.js"></script><!-- hexo injector body_end end --></body></html>